<template>
  <div class="wrap">
    <el-card>
      <el-form size="mini" ref="photovoltaic" label-width="120px" :model="photovoltaicForm">
        <el-row type="flex" justify="space-between">
          <el-col :span="5">
            <el-form-item label="调度:">
              <el-select v-model="photovoltaicForm.regulationOrgId" placeholder="请选择调度" clearable>
                <el-option v-for="item in dispatchList" :key="item.value" :label="item.label" :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="升压站接入等级:">
              <el-select v-model="photovoltaicForm.voltageLevelCode" placeholder="请选择升压站接入等级" clearable>
                <el-option v-for="item in LevelOfAccessList" :key="item.value" :label="item.label" :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="场站名称:">
              <el-input v-model.trim="photovoltaicForm.stationName" placeholder="请输入场站名称" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="产权单位:">
              <el-input v-model.trim="photovoltaicForm.ownersName" placeholder="请输入业主单位" clearable></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex" justify="space-between">
          <el-col :span="5">
            <el-form-item label="是否已整站投产:">
              <el-select v-model="photovoltaicForm.isProduction" placeholder="请选择是否已整站投产" clearable>
                <el-option v-for="item in yesOrNo" :key="item.value" :label="item.label" :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="整站容量范围:">
              <el-input
                v-model.trim="photovoltaicForm.capStart"
                clearable
                type="number"
                oninput="value= value.length>40?value.slice(0,40):value"
                style="width: calc(50% - 22px)"
              ></el-input>
              <span style="padding-right: 5px; padding-left: 5px">-</span>
              <el-input
                v-model.trim="photovoltaicForm.capEnd"
                type="number"
                oninput="value= value.length>40?value.slice(0,40):value"
                clearable
                style="width: calc(50% - 22px)"
              ></el-input
              ><span style="margin-left: 5px; font-size: 12px">MW</span>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="整站投产时间:">
              <el-date-picker
                v-model="photovoltaicForm.productionTime"
                type="date"
                style="width: 100%"
                :value-format="'yyyy-MM-dd'"
                placeholder="选择日期"
                clearable
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="是否已投入:">
              <el-select v-model="photovoltaicForm.isRegulation" placeholder="请选择是否已投入" clearable :popper-append-to-body="false">
                <el-option v-for="item in yesOrNo" :key="item.value" :label="item.label" :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="5">
            <el-form-item label="上调下调是否投入:">
              <el-select v-model="photovoltaicForm.adjustRegulationCode" placeholder="请选择上调下调是否投入" clearable>
                <el-option v-for="item in adjustRegulationList" :key="item.value" :label="item.label" :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="是否具备惯量响应:" style="margin-left: 22%">
              <el-select v-model="photovoltaicForm.isResponse" placeholder="请选择是否具备惯量响应" clearable style="width: 110%">
                <el-option v-for="item in yesOrNo" :key="item.value" :label="item.label" :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-button style="margin-left: 37%" type="primary" size="mini" @click="searchList">检索</el-button>
            <el-button size="mini" @click="resetSearchList">重置</el-button>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    <el-card style="margin-top: 20px">
      <CleanForm
        :showColumnHandle="false"
        :searShow="true"
        :showColumnSetting="false"
        :showCheckbox="true"
        :showIndex="true"
        :showExportBtn="false"
        :field-list="fieldList"
        :api="getQueryEnergyStationInfo"
        :queryParam="photovoltaicForm"
        tableOptionWidth="100"
        ref="photovoltaicTable"
        :tableHeight="'calc(100vh - 400px)'"
        :page="false"
        :dialogPage="true"
      >
        <!-- :dialogPage = "true" -->
        <template slot="tableTopOptionRight">
          <!-- 这里是写表格上方的按钮 -->
          <!-- <el-button  type="primary" @click="openAddDialog" >新增</el-button>
        <el-button  type="primary"  @click="openCopyDialog" >复制</el-button>
        <el-button  type="primary"  @click="openEditDialog" >编辑</el-button>
        <el-button  type="primary" >删除</el-button>
        <el-button  type="primary" >导出</el-button> -->
          <div>
            <!-- <span class="operateButton" @click="openAddDialog"
              ><img src="@/assets/icon/389.png" /> 新增</span
            > -->
            <span class="operateButton" @click="openCopyDialog"><img src="@/assets/icon/394.png" /> 复制</span>
            <span class="operateButton" @click="openEditDialog"><img src="@/assets/icon/392.png" /> 编辑</span>
            <span class="operateButton" @click="doDelete"><img src="@/assets/icon/393.png" /> 删除</span>
            <span style="padding-top: 10px" class="operateButton" @click="exportExcel()"><img src="@/assets/icon/395.png" /> 导出</span>
          </div>
        </template>
      </CleanForm>
    </el-card>
    <!-- 新增-复制-编辑弹窗 -->
    <el-dialog :title="addDialogVisibleTitle" :visible.sync="addDialogVisible" width="1500px" top="5vh" :close-on-click-modal="false">
      <el-form :model="dialogForm" size="mini" ref="diaForm" :rules="dialogFormRule" v-if="addDialogVisible" label-width="150px">
        <!-- 基本信息 -->
        <h5 class="titleText">基本信息</h5>
        <el-row type="flex">
          <el-col :span="6">
            <el-form-item label="所属调管调度机构:" prop="regulationOrgId">
              <el-select v-model="dialogForm.regulationOrgId" size="mini" clearable placeholder="请选择所属调管调度机构" :disabled="disabledSelect">
                <el-option
                  v-for="item in dispatchList.filter((item) => item.label !== '全部')"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="场站名称:" size="mini" prop="regulationOrgId">
              <el-input
                v-model.trim="dialogForm.stationName"
                autocomplete="off"
                size="mini"
                clearable
                maxlength="40"
                placeholder="请输入场站名称"
              ></el-input>
              <!-- <SelectAdd
                :labelslist="stationList"
                label="stationName"
                val="stationId"
                :api="getInsertStationInfo"
                query="stationName"
                order="场站名称"
                :formVla="dialogForm.stationId"
                ref="station"
                :regulationOrgId="dialogForm.regulationOrgId"
                regulation="regulationOrgId"
                stationCategory="2"
                :stationTypes="photovoltaicForm.stationType"
                @getQueryStationList="getQueryStationList"
              ></SelectAdd> -->
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <!-- 升压站接入等级 -->
            <el-form-item size="mini" label="升压站接入等级:" prop="voltageLevelCode">
              <el-select v-model="dialogForm.voltageLevelCode" size="mini" clearable placeholder="请选择升压站接入等级">
                <el-option
                  v-for="item in LevelOfAccessList.filter((item) => item.label !== '全部')"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="产权单位:" size="mini">
              <!-- <el-select
                v-model="dialogForm.ownersId"
                size="mini"
                placeholder="请选择业主单位"
              >
                <el-option
                  v-for="item in ownersList"
                  :key="item.ownersId"
                  :label="item.ownersName"
                  :value="item.ownersId"
                >
                </el-option>
              </el-select> -->
              <SelectAdd
                :labelslist="ownersList"
                label="ownersName"
                ref="owner"
                val="ownersId"
                :api="getInsertOwnersInfo"
                query="ownersId"
                order="产权单位"
                :formVla="dialogForm.ownersId"
                @getQueryStationList="getOwnersList"
                :delApi="deleteOwnersInfo"
              >
              </SelectAdd>
              <!-- :disabledSelect=disabledSelect -->
            </el-form-item>
          </el-col>
        </el-row>
        <h5 class="titleText">整站投产情况</h5>
        <el-row type="flex">
          <el-col :span="6">
            <!-- 是否已整站投产 -->
            <el-form-item label="是否已整站投产:" size="mini" prop="isProduction">
              <el-select v-model="dialogForm.isProduction" size="mini" clearable placeholder="请选择是否已整站投产">
                <el-option v-for="item in yesOrNo" :key="item.value" :label="item.label" :value="item.value"> </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="整站容量:" size="mini">
              <el-input
                v-model.trim="dialogForm.stationCap"
                autocomplete="off"
                size="mini"
                type="number"
                clearable
                oninput="value= value.length>40?value.slice(0,40):value"
                placeholder="请输入整站容量"
                style="width: calc(100% - 28px); margin-right: 1%"
              ></el-input
              >MW
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="整站投产时间:" size="mini">
              <el-date-picker
                v-model="dialogForm.productionTime"
                type="date"
                :value-format="'yyyy-MM-dd'"
                style="width: 100%"
                placeholder="请选择整站投产时间"
                clearable
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <h5 class="titleText">文件上传</h5>
        <el-row>
          <el-col :span="12">
            <el-form-item label="一次调频实验方案:" size="mini">
              <el-upload
                ref="upload"
                action="#"
                class="upload-demo"
                :on-change="onChange2"
                :multiple="false"
                :limit="2"
                :on-exceed="handleExceed"
                :file-list="fileList2"
                :http-request="uploadHttpReq"
                :auto-upload="false"
                :show-file-list="false"
              >
                <div>
                  <el-button size="mini">选择文件</el-button>
                </div>
              </el-upload>
              <el-tooltip
                class="item"
                effect="dark"
                :content="dialogForm.regulationTestPlan"
                placement="top"
                :disabled="dialogForm.regulationTestPlan ? false : true"
              >
                <el-input
                  v-model.trim="dialogForm.regulationTestPlan"
                  clearable
                  style="width: 65%"
                  placeholder="仅支持pdf、excel格式的文件"
                  disabled
                ></el-input>
              </el-tooltip>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="上传时间:" size="mini">
              <el-date-picker
                v-model="dialogForm.regulationTime2"
                type="datetime"
                placeholder="选择日期"
                style="width: 65%"
                :value-format="'yyyy-MM-dd HH:mm:ss'"
                disabled
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="一次调频测试报告:" size="mini">
              <el-upload
                ref="upload"
                action="#"
                class="upload-demo"
                :on-change="onChange3"
                :multiple="false"
                :limit="2"
                :on-exceed="handleExceed"
                :file-list="fileList3"
                :http-request="uploadHttpReq"
                :auto-upload="false"
                :show-file-list="false"
              >
                <div>
                  <el-button size="mini">选择文件</el-button>
                </div>
              </el-upload>
              <el-tooltip
                class="item"
                effect="dark"
                :content="dialogForm.regulationTestReport"
                placement="top"
                :disabled="dialogForm.regulationTestReport ? false : true"
              >
                <el-input
                  v-model.trim="dialogForm.regulationTestReport"
                  style="width: 65%"
                  placeholder="仅支持pdf、excel格式的文件"
                  clearable
                  disabled
                ></el-input>
              </el-tooltip>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="上传时间:" size="mini">
              <el-date-picker
                v-model="dialogForm.regulationTime3"
                type="datetime"
                placeholder="选择日期"
                style="width: 65%"
                :value-format="'yyyy-MM-dd HH:mm:ss'"
                disabled
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="一次调频定值单:" size="mini">
              <el-upload
                ref="upload1"
                action="#"
                class="upload-demo"
                :on-change="onChange1"
                :before-upload="beforeAvatarUpload"
                :multiple="false"
                :limit="2"
                :on-exceed="handleExceed"
                :file-list="fileList1"
                :http-request="uploadHttpReq"
                :auto-upload="false"
                :show-file-list="false"
                :disabled="flagUpload"
              >
                <div>
                  <el-button @click="regulationReportFormChange" size="mini">选择文件</el-button>
                </div>
              </el-upload>
              <el-tooltip
                class="item"
                effect="dark"
                :content="dialogForm.regulationReportForm"
                placement="top"
                :disabled="dialogForm.regulationReportForm ? false : true"
              >
                <el-input
                  v-model.trim="dialogForm.regulationReportForm"
                  style="width: 65%"
                  placeholder="仅支持pdf、excel格式的文件"
                  disabled
                  clearable
                ></el-input>
              </el-tooltip>
              <p style="font-size: 12px !important; color: red" v-if="dialogForm.isDelay == '1'">(已滞后两周,请尽快上传)</p>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="上传时间:" size="mini">
              <el-date-picker
                v-model="dialogForm.regulationTime1"
                type="datetime"
                placeholder="选择日期"
                style="width: 65%"
                :value-format="'yyyy-MM-dd HH:mm:ss'"
                disabled
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="惯量响应方案:" size="mini">
              <el-upload
                ref="upload"
                action="#"
                class="upload-demo"
                :on-change="onChange4"
                :multiple="false"
                :limit="2"
                :on-exceed="handleExceed"
                :file-list="fileList4"
                :http-request="uploadHttpReq"
                :auto-upload="false"
                :show-file-list="false"
              >
                <div>
                  <el-button size="mini">选择文件</el-button>
                </div>
              </el-upload>
              <el-tooltip
                class="item"
                effect="dark"
                :content="dialogForm.responsePlan"
                placement="top"
                :disabled="dialogForm.responsePlan ? false : true"
              >
                <el-input
                  v-model.trim="dialogForm.responsePlan"
                  style="width: 65%"
                  placeholder="仅支持pdf、excel格式的文件"
                  disabled
                  clearable
                ></el-input>
              </el-tooltip>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="上传时间:" size="mini">
              <el-date-picker
                v-model="dialogForm.regulationTime4"
                type="datetime"
                placeholder="选择日期"
                style="width: 65%"
                :value-format="'yyyy-MM-dd HH:mm:ss'"
                disabled
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="惯量响应报告:" size="mini">
              <el-upload
                ref="upload"
                action="#"
                class="upload-demo"
                :on-change="onChange5"
                :multiple="false"
                :limit="2"
                :on-exceed="handleExceed"
                :file-list="fileList5"
                :http-request="uploadHttpReq"
                :auto-upload="false"
                :show-file-list="false"
              >
                <div>
                  <el-button size="mini">选择文件</el-button>
                </div>
              </el-upload>
              <el-tooltip
                class="item"
                effect="dark"
                :content="dialogForm.responseReport"
                placement="top"
                :disabled="dialogForm.responseReport ? false : true"
              >
                <el-input
                  v-model.trim="dialogForm.responseReport"
                  style="width: 65%"
                  placeholder="仅支持pdf、excel格式的文件"
                  disabled
                  clearable
                ></el-input>
              </el-tooltip>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="上传时间:" size="mini">
              <el-date-picker
                v-model="dialogForm.regulationTime5"
                type="datetime"
                placeholder="选择日期"
                style="width: 65%"
                :value-format="'yyyy-MM-dd HH:mm:ss'"
                disabled
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <h5 class="titleText">一次调频功能及惯量响应建设情况</h5>
        <el-row type="flex">
          <el-col :span="6">
            <!-- 是否已投入 -->
            <el-form-item label="是否已投入:" size="mini" prop="isRegulation">
              <el-select v-model="dialogForm.isRegulation" size="mini" clearable placeholder="请选择是否已投入" @change="isRegulationChange">
                <el-option v-for="item in yesOrNo" :key="item.value" :label="item.label" :value="item.value"> </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="投入时间:" size="mini">
              <el-date-picker
                v-model="dialogForm.regulationTime"
                type="datetime"
                :value-format="'yyyy-MM-dd HH:mm:ss'"
                style="width: 100%"
                placeholder="请选择投入时间"
                clearable
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="未按期投入原因:" size="mini">
              <el-input
                v-model.trim="dialogForm.unRegulateReason"
                autocomplete="off"
                size="mini"
                maxlength="40"
                placeholder="请输入未按期投入原因"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <!-- 上调/下调是否投入 -->
            <el-form-item label="上调/下调是否投入:" size="mini">
              <el-select v-model="dialogForm.adjustRegulationCode" size="mini" placeholder="请选择上调/下调是否投入" clearable>
                <el-option
                  v-for="item in adjustRegulationList.filter((item) => item.label !== '全部')"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex">
          <el-col :span="6">
            <!-- 是否完成惯量响应测试 -->

            <el-form-item label="是否完成惯量响应测试:" size="mini">
              <el-select v-model="dialogForm.isResponse" size="mini" clearable placeholder="请选择是否完成惯量响应测试">
                <el-option v-for="item in yesOrNo" :key="item.value" :label="item.label" :value="item.value"> </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="试验单位:" size="mini">
              <!-- <el-input
                v-model.trim="dialogForm.testingUnitCode"
                autocomplete="off"
                size="mini"
                maxlength="40"
                clearable
                placeholder="请输入试验单位"
              ></el-input> -->

              <!-- <el-select
                v-model="dialogForm.testingUnitCode"
                size="mini"
                clearable
                placeholder="请选择试验单位"
              >
                <el-option
                  v-for="item in queryUnitList"
                  :key="item.testingUnitId"
                  :label="item.testingUnitName"
                  :value="item.testingUnitId"
                >
                </el-option>
              </el-select> -->
              <SelectAdd
                :labelslist="queryUnitList"
                label="testingUnitName"
                ref="testingUnit"
                val="testingUnitId"
                :formVla="dialogForm.testingUnitId"
                :api="getInsertTestingUnitInfo"
                query="testingUnitId"
                order="试验单位"
                :delApi="deleteTestingUnitInfo"
                @getQueryStationList="getQueryTestingUnitList"
              ></SelectAdd>
              <!-- :disabledSelect=disabledSelect -->
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 一次调频值明细及功能要求(功能未投入的场站留空) -->
        <h5 class="titleText">一次调频值明细及功能要求(功能未投入的场站留空)</h5>
        <el-row type="flex">
          <el-col :span="6">
            <el-form-item label="死区:" size="mini" prop="deadZone">
              <span style="font-size: 18px"> ± </span>
              <el-input
                v-model.trim="dialogForm.deadZone"
                autocomplete="off"
                size="mini"
                clearable
                :controls="false"
                type="number"
                oninput="value= typeof(value)=='number' ? (value.length>40?value.slice(0,40):value) : value.replace(/[^\d.]/g,'')"
                placeholder="请输入死区"
                :disabled="disabledDetail"
                style="width: calc(100% - 42px); margin-right: 1%"
              ></el-input
              >Hz
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="调差系数:" size="mini" prop="adjustRatio">
              <el-input
                v-model.trim="dialogForm.adjustRatio"
                autocomplete="off"
                size="mini"
                clearable
                type="number"
                oninput="value= value.length>40?value.slice(0,40):value"
                :disabled="disabledDetail"
                placeholder="请输入调差系数"
                style="width: calc(100% - 42px); margin-right: 1%"
              ></el-input
              >%
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="启动功率门槛:" size="mini" prop="startingPowerThreshold">
              <span style="font-size: 18px">&nbsp;&nbsp;&nbsp;</span>
              <el-input
                v-model.trim="dialogForm.startingPowerThreshold"
                autocomplete="off"
                size="mini"
                clearable
                type="number"
                :disabled="disabledDetail"
                oninput="value= value.length>40?value.slice(0,40):value"
                placeholder="请输入启动功率门槛"
                style="width: calc(100% - 42px); padding-right: 1%"
              ></el-input
              >MW
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="下调限幅：" size="mini" prop="lowerLimit">
              <span style="font-size: 18px">&nbsp;&nbsp;&nbsp;</span>
              <el-input
                v-model.trim="dialogForm.lowerLimit"
                autocomplete="off"
                size="mini"
                clearable
                type="number"
                :disabled="disabledDetail"
                oninput="value= value.length>40?value.slice(0,40):value"
                placeholder="请输入启动下调限幅"
                style="width: calc(100% - 42px); padding-right: 1%"
              ></el-input
              >MW
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex">
          <el-col :span="6">
            <el-form-item label="功率调节偏差:" size="mini" prop="powerAdjustDeviation">
              <!-- 空格 -->
              <el-input
                v-model.trim="dialogForm.powerAdjustDeviation"
                autocomplete="off"
                size="mini"
                clearable
                type="number"
                :disabled="disabledDetail"
                oninput="value= value.length>40?value.slice(0,40):value"
                placeholder="请输入功率调节偏差"
                style="width: calc(100% - 42px); padding-right: 1%; transform: transLateX(15px)"
              ></el-input
              ><span style="transform: transLateX(15px); display: inline-block">MW</span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="上调限幅:" size="mini" prop="upLimit">
              <el-input
                v-model.trim="dialogForm.upLimit"
                autocomplete="off"
                size="mini"
                clearable
                :disabled="disabledDetail"
                oninput="value= value.length>40?value.slice(0,40):value"
                type="number"
                placeholder="请输入上调限幅"
                style="width: calc(100% - 42px); padding-right: 1%"
              ></el-input
              >MW
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="启动时间:" size="mini" prop="startTime">
              <span style="font-size: 18px">≤ </span>
              <el-input
                v-model.trim="dialogForm.startTime"
                autocomplete="off"
                size="mini"
                clearable
                :disabled="disabledDetail"
                oninput="value= value.length>40?value.slice(0,40):value"
                type="number"
                placeholder="请输入启动时间"
                style="width: calc(100% - 42px)"
              ></el-input
              ><span style="font-size: 14px"> s </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="响应时间:" size="mini" prop="responseTime">
              <span style="font-size: 18px"> ≤ </span>
              <el-input
                v-model.trim="dialogForm.responseTime"
                autocomplete="off"
                size="mini"
                oninput="value= value.length>40?value.slice(0,40):value"
                clearable
                :disabled="disabledDetail"
                maxlength="40"
                placeholder="请输入响应时间"
                style="width: calc(100% - 42px)"
              ></el-input>
              <span style="font-size: 14px"> s </span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex">
          <el-col :span="6">
            <el-form-item label="调节时间:" size="mini" prop="adjustTime">
              <span style="font-size: 18px"> ≤ </span>
              <el-input
                v-model.trim="dialogForm.adjustTime"
                autocomplete="off"
                size="mini"
                oninput="value= value.length>40?value.slice(0,40):value"
                type="number"
                :disabled="disabledDetail"
                clearable
                placeholder="输入调节时间"
                style="width: calc(100% - 42px)"
              ></el-input
              ><span style="font-size: 14px"> s </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="一次调频投退功能:" size="mini" prop="onOffFunction">
              <el-select
                v-model="dialogForm.onOffFunction"
                size="mini"
                placeholder="请选择"
                clearable
                style="width: calc(100% - 42px)"
                :disabled="disabledDetail"
              >
                <el-option v-for="item in isEnable" :key="item.value" :label="item.label" :value="item.value"> </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="一次调频上调功能:" size="mini" prop="isUpFunction">
              <el-select
                v-model="dialogForm.isUpFunction"
                size="mini"
                placeholder="请选择"
                clearable
                style="width: calc(100% - 42px); margin-left: 15px"
                :disabled="disabledDetail"
              >
                <el-option v-for="item in isEnable" :key="item.value" :label="item.label" :value="item.value"> </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="一次调频下调功能:" size="mini" prop="isLowerFunction">
              <el-select
                v-model="dialogForm.isLowerFunction"
                size="mini"
                placeholder="请选择"
                clearable
                style="width: calc(100% - 42px); margin-left: 15px"
                :disabled="disabledDetail"
              >
                <el-option v-for="item in isEnable" :key="item.value" :label="item.label" :value="item.value"> </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex">
          <el-col :span="6">
            <el-form-item label="惯量响应功能:" size="mini" prop="isResponseFunction">
              <el-select
                v-model="dialogForm.isResponseFunction"
                size="mini"
                placeholder="请选择"
                clearable
                style="width: calc(100% - 42px); margin-left: 15px"
                :disabled="disabledDetail"
              >
                <el-option v-for="item in isResponseList" :key="item.value" :label="item.label" :value="item.value"> </el-option>
              </el-select>
            </el-form-item> </el-col
          ><el-col :span="6">
            <el-form-item label="一次调频与AGC协调控制:" size="mini" prop="agcControl">
              <el-select
                v-model="dialogForm.agcControl"
                size="mini"
                placeholder="请选择"
                clearable
                style="width: calc(100% - 42px)"
                :disabled="disabledDetail"
              >
                <el-option v-for="item in agcControlList" :key="item.value" :label="item.label" :value="item.value"> </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" style="text-align: end">
        <el-button size="small" type="primary" @click="isAdd">{{ this.addDialogVisibleTitle == '编辑' ? '确认编辑' : '确认新增' }}</el-button>
        <el-button v-if="this.addDialogVisibleTitle != '编辑'" size="small" @click="isReset">重置</el-button>
        <el-button size="small" @click="isExit">退出</el-button>
      </div>
    </el-dialog>
    <!-- 预览弹框 -->
    <el-dialog
      title="预览"
      top="8vh"
      width="70%"
      :visible.sync="dialogPreVisible"
      @close="
        () => {
          pdf = ''
        }
      "
    >
      <iframe
        style="width: 100%; height: 450px"
        frameborder="0"
        width="100%"
        height="620px"
        :src="pdf"
        v-if="pdf"
        type="application/x-google-chrome-pdf"
        ref="previewFrame"
      ></iframe>
      <div class="table-html-wrap" v-if="!pdf" style="width: 100%; height: 420px; overflow: auto" id="tableHtml"></div>
    </el-dialog>
  </div>
</template>
<script>
// import '@/mock/data'
import {
  getPhotovoltaicList,
  getQueryEnergyStationInfo,
  getInsertEnergyStationInfo,
  doInsertOrUpdateEnergyStationInfo,
  downloadEnergyStationInfos,
  deleteEnergyStationInfo,
} from '@/api/photovoltaic'
import {
  regulationOrgList,
  voltageLevelList,
  queryOwnersList,
  queryTestingUnitList,
  queryStationList,
  getInsertStationInfo,
  getInsertTestingUnitInfo,
  getInsertOwnersInfo,
  adjustRegulationList,
  deleteOwnersInfo,
  deleteTestingUnitInfo,
  agcControlList,
} from '@/api/dict'
import { getPdf } from '@/api/windPower.js'
import * as XLSX from 'xlsx'

export default {
  name: 'photovoltaic',
  data() {
    let yesOrNoList = {
      0: '否',
      1: '是',
    }
    let enableList = {
      0: '退出',
      1: '启用',
    }
    let isResponseList = {
      0: '暂未开展惯量响应试验',
    }
    let validForm = (rule, value, callback) => {
      if (!value && this.dialogForm.isRegulation == '1') {
        callback(new Error(rule.message))
      } else {
        callback()
      }
    }
    return {
      formData: new FormData(),
      getPhotovoltaicList,
      getQueryEnergyStationInfo,
      getInsertStationInfo,
      getInsertOwnersInfo,
      getInsertTestingUnitInfo,
      deleteTestingUnitInfo,
      deleteOwnersInfo,
      // stationCategory:'2',
      disabledDetail: false,
      ownersList: [],
      queryUnitList: [],
      stationList: [],
      agcControlList: [], //协调控制
      adjustRegulationList: [],
      addDialogVisible: false,
      addDialogVisibleTitle: '新增',
      dialogForm: {},
      pdf: '', //设置文档地址
      fileList1: [], //展示的文件列表,
      fileList2: [], //展示的文件列表,
      fileList3: [], //展示的文件列表,
      fileList4: [], //展示的文件列表,
      fileList5: [], //展示的文件列表,
      flagUpload: true,
      // 预览弹框
      dialogPreVisible: false,
      dialogFormRule: {
        regulationOrgId: [
          {
            required: true,
            message: '请选择所属调管调度机构',
            trigger: 'change',
          },
        ],
        stationId: [{ required: true, message: '请输入场站名称', trigger: 'change' }],
        isProduction: [
          {
            required: true,
            message: '请选择是否已整站投入',
            trigger: 'change',
          },
        ],
        isRegulation: [{ required: true, message: '请选择是否已投入', trigger: 'change' }],
        voltageLevelCode: [
          {
            required: true,
            message: '请选择升压站接入等级',
            trigger: 'change',
          },
        ],
        deadZone: [{ validator: validForm, message: '请输入死区', trigger: 'change' }],
        adjustRatio: [
          {
            validator: validForm,
            message: '请输入调差系数',
            trigger: 'change',
          },
        ],
        startingPowerThresholdL: [
          {
            validator: validForm,
            message: '请输入启动功率门槛',
            trigger: 'change',
          },
        ],
        lowerLimit: [
          {
            validator: validForm,
            message: '请输入启动下调限幅',
            trigger: 'change',
          },
        ],
        powerAdjustDeviation: [
          {
            validator: validForm,
            message: '请输入功率调节偏差',
            trigger: 'change',
          },
        ],
        upLimit: [
          {
            validator: validForm,
            message: '请输入上调限幅',
            trigger: 'change',
          },
        ],
        startTime: [
          {
            validator: validForm,
            message: '请输入启动时间',
            trigger: 'change',
          },
        ],
        responseTime: [
          {
            validator: validForm,
            message: '请输入响应时间',
            trigger: 'change',
          },
        ],
        adjustTime: [
          {
            validator: validForm,
            message: '请输入调节时间',
            trigger: 'change',
          },
        ],
        onOffFunction: [
          {
            validator: validForm,
            message: '请选择一次调频投退功能',
            trigger: 'change',
          },
        ],
        isUpFunction: [
          {
            validator: validForm,
            message: '请选择一次调频上调功能',
            trigger: 'change',
          },
        ],
        isLowerFunction: [
          {
            validator: validForm,
            message: '请选择一次调频下调功能',
            trigger: 'change',
          },
        ],
        isResponseFunction: [
          {
            validator: validForm,
            message: '请选择惯量响应功能',
            trigger: 'change',
          },
        ],
        agcControl: [
          {
            validator: validForm,
            message: '请选择一次调频与AGC协调控制',
            trigger: 'change',
          },
        ],
      },
      photovoltaicForm: {
        regulationOrgCode: '',
        regulationOrgId: '',
        voltageLevelCode: '',
        stationName: '',
        ownersName: '',
        isProduction: '',
        capStart: '',
        capEnd: '',
        productionTime: '',
        isRegulation: '',
        isResponse: '',
        adjustRegulationCode: '',
        stationType: '6',
      },
      dialogForm: {
        regulationOrgId: '1',
        regulationId: '',
        voltageLevelCode: '110',
        ownersId: '',
        isProduction: '1',
        stationCap: '',
        productionTime: '',
        isRegulation: '1',
        regulationTime: '',
        unRegulateReason: '',
        adjustRegulationCode: '',
        isResponse: '',
        stationId: '',
        stationName: '',
        testingUnitId: '',
        deadZone: '',
        adjustRatio: '',
        startingPowerThresholdL: '',
        lowerLimit: '',
        powerAdjustDeviation: '',
        upLimit: '',
        startTime: '',
        responseTime: '',
        adjustTime: '',
        stationType: '6',
        operateCode: '',
        onOffFunction: '',
        isUpFunction: '',
        isLowerFunction: '',
        isResponseFunction: '',
        agcControl: '',
      },
      dispatchList: [
        {
          label: '广西中调',
          value: '1',
        },
        {
          label: '云南中调',
          value: '2',
        },
        {
          label: '广东中调',
          value: '3',
        },
      ],
      LevelOfAccessList: [
        {
          label: '110',
          value: '1',
        },
        {
          label: '220',
          value: '2',
        },
      ],
      yesOrNo: [
        {
          label: '是',
          value: '1',
        },
        {
          label: '否',
          value: '0',
        },
      ],
      isEnable: [
        {
          label: '启用',
          value: '1',
        },
        {
          label: '退出',
          value: '0',
        },
      ],
      isResponseList: [
        {
          label: '暂未开展惯量响应试验',
          value: '0',
        },
      ],

      fieldList: [
        { name: '所属调管调度机构', value: 'regulationOrgName', noSort: true },
        { name: '场站名称', value: 'stationName', noSort: true },
        { name: '升压站接入电压等级', value: 'voltageLevelName', noSort: true },
        { name: '产权单位', value: 'ownersName', noSort: true },
        {
          name: '是否已整站投产',
          value: 'isProduction',
          noSort: true,
          formatter: (row) => (yesOrNoList[row.isProduction] ? yesOrNoList[row.isProduction] : ''),
        }, //存疑
        {
          name: '整站容量',
          value: 'stationCap',
          noSort: true,
          formatter: (row) => (row.stationCap ? `${row.stationCap}MW` : ''),
        },
        { name: '整站投产时间', value: 'productionTime', noSort: true },
        {
          name: '是否已投入',
          value: 'isRegulation',
          noSort: true,
          formatter: (row) => (yesOrNoList[row.isRegulation] ? yesOrNoList[row.isRegulation] : ''),
        }, //存疑，返回值是哪个字段？
        {
          name: '投入时间',
          value: 'regulationTime',
          noSort: true,
          formatter: (row) => (row.regulationTime ? row.regulationTime.replace('T', ' ') : ''),
        },
        { name: '未按期投入原因', value: 'unRegulateReason', noSort: true },
        {
          name: '上调/下调是否投入',
          value: 'adjustRegulationName',
          noSort: true,
        },
        {
          name: '是否具备惯量响应',
          value: 'isResponse',
          noSort: true,
          formatter: (row) => (yesOrNoList[row.isResponse] ? yesOrNoList[row.isResponse] : ''),
        }, //存疑
        { name: '试验单位', value: 'testingUnitName', noSort: true },
        {
          name: '死区',
          value: 'deadZone',
          noSort: true,
          formatter: (row) => (row.deadZone ? `±${row.deadZone}Hz` : ''),
        },
        {
          name: '调差系数',
          value: 'adjustRatio',
          noSort: true,
          formatter: (row) => (row.adjustRatio ? `${row.adjustRatio}%` : ''),
        }, //存疑，返回值是哪个字段？
        {
          name: '启动功率门槛',
          value: 'startingPowerThreshold',
          noSort: true,
          formatter: (row) => (row.startingPowerThreshold ? `${row.startingPowerThreshold}MW` : ''),
        },
        {
          name: '下调限幅',
          value: 'lowerLimit',
          noSort: true,
          formatter: (row) => (row.lowerLimit ? `${row.lowerLimit}MW` : ''),
        },
        {
          name: '上调限幅',
          value: 'upLimit',
          noSort: true,
          formatter: (row) => (row.upLimit ? `${row.upLimit}MW` : ''),
        },
        {
          name: '启动时间',
          value: 'startTime',
          noSort: true,
          formatter: (row) => (row.startTime ? `≤${row.startTime}s` : ''),
        },
        {
          name: '响应时间',
          value: 'responseTime',
          noSort: true,
          formatter: (row) => (row.responseTime ? `≤${row.responseTime}s` : ''),
        },
        {
          name: '调节时间',
          value: 'adjustTime',
          noSort: true,
          formatter: (row) => (row.adjustTime ? `≤${row.adjustTime}s` : ''),
        },
        {
          name: '功率调节偏差',
          value: 'powerAdjustDeviation',
          noSort: true,
          formatter: (row) => (row.powerAdjustDeviation ? `${row.powerAdjustDeviation}MW` : ''),
        },
        {
          name: '一次调频投退功能',
          value: 'onOffFunction',
          noSort: true,
          formatter: (row) => (enableList[row.onOffFunction] ? enableList[row.onOffFunction] : ''),
        },
        {
          name: '一次调频上调功能',
          value: 'isUpFunction',
          noSort: true,
          formatter: (row) => (enableList[row.isUpFunction] ? enableList[row.isUpFunction] : ''),
        },
        {
          name: '一次调频下调功能',
          value: 'isLowerFunction',
          noSort: true,
          formatter: (row) => (enableList[row.isLowerFunction] ? enableList[row.isLowerFunction] : ''),
        },
        {
          name: '惯量响应功能',
          value: 'isResponseFunction',
          noSort: true,
          formatter: (row) => (isResponseList[row.isResponseFunction] ? isResponseList[row.isResponseFunction] : ''),
        },
        {
          name: '一次调频与AGC协调控制',
          value: 'agcControlName',
          noSort: true,
        },
        {
          name: '一次调频实验方案',
          value: 'regulationTestPlan',
          order: 'regulationTestPlanId',
          noSort: true,
          type: 'linkPreview',
          clickPreview: this.doPreview,
          clickDownload: this.doDownload,
        },
        {
          name: '实验方案上传时间',
          value: 'regulationTime1',
          noSort: true,
          formatter: (row) => (row.regulationTestPlan ? row.regulationTestPlan.createTime.replace('T', ' ') : ''),
        },
        {
          name: '一次调频测试报告',
          value: 'regulationTestReport',
          order: 'regulationTestReportId',
          noSort: true,
          type: 'linkPreview',
          clickPreview: this.doPreview,
          clickDownload: this.doDownload,
        },
        {
          name: '测试报告上传时间',
          value: 'regulationTime3',
          noSort: true,
          formatter: (row) => (row.regulationTestReport ? row.regulationTestReport.createTime.replace('T', ' ') : ''),
        },
        {
          name: '一次调频定值单',
          value: 'regulationReportForm',
          order: 'regulationReportFormId',
          noSort: true,
          type: 'linkPreview',
          clickPreview: this.doPreview,
          clickDownload: this.doDownload,
        },
        {
          name: '定值单上传时间',
          value: 'regulationTime2',
          noSort: true,
          formatter: (row) => (row.regulationReportForm ? row.regulationReportForm.createTime.replace('T', ' ') : ''),
        },
        {
          name: '是否滞后',
          value: 'isDelay',
          noSort: true,
          fontColor: true,
          formatter: (row) => (yesOrNoList[row.isDelay] ? yesOrNoList[row.isDelay] : ''),
        },
        {
          name: '惯量响应方案',
          value: 'responsePlan',
          order: 'responsePlanId',
          noSort: true,
          type: 'linkPreview',
          clickPreview: this.doPreview,
          clickDownload: this.doDownload,
        },
        {
          name: '惯量响应报告',
          value: 'responseReport',
          order: 'responseReportId',
          noSort: true,
          type: 'linkPreview',
          clickPreview: this.doPreview,
          clickDownload: this.doDownload,
        },

        // { name: "场站类型编码", value: "stationType", noSort: true },
        // { name: "场站类型名称", value: "stationTypeName", noSort: true },
        // { name: "机组名称", value: "unitsName", noSort: true },
        // { name: "机组编号", value: "unitsNumber", noSort: true },
      ],
    }
  },
  mounted() {},
  created() {
    this.getRegulationOrgList()
    this.getVoltageLevelList()
    this.getOwnersList()
    this.getQueryTestingUnitList()
    this.getAgcControlList()
    this.getAdjustRegulationList()
  },
  computed: {
    disabledSelect() {
      return this.addDialogVisibleTitle === '编辑'
    },
  },
  methods: {
    handleExceed() {},
    uploadHttpReq(file) {},
    inputNumber(e) {
      console.log(e)
      // return e.length>41?e.slice(0,40):e
    },
    // 文件上传前
    beforeAvatarUpload(file) {
      const isJPG = file.type === 'xlsx'
      if (!isJPG) {
        this.$message.error('文件上传只能是 Pdf/Excel(xlxs、xls) 格式!')
        return false
      } else {
        return true
      }
    },
    onChange1(file, fileList1) {
      // 上传单个文件且能覆盖之前的文件
      if (fileList1.length > 0) {
        this.fileList1 = [fileList1[fileList1.length - 1]] // 获取最后一次选择的文件
      }

      // 获取当前时间
      let dateTime = new Date()
      this.dialogForm.regulationTime1 = this.$dayjs(dateTime).format('YYYY-MM-DD HH:mm:ss')

      // 上传文件类型的限制
      let testFile = file.name.substring(file.name.lastIndexOf('.') + 1).toLowerCase()
      const extension = testFile === 'xlsx' || testFile === 'xls' || testFile === 'pdf'
      if (!extension) {
        this.$message.error('文件上传只能是 pdf/Excel(xlxs、xls) 格式!')
        return false
      } else {
        this.dialogForm.regulationReportForm = file.name
        this.formData.set('regulationReportForm', file.raw)
        return true
      }
    },

    onChange2(file, fileList2) {
      // 上传单个文件且能覆盖之前的文件
      if (fileList2.length > 0) {
        this.fileList2 = [fileList2[fileList2.length - 1]] // 获取最后一次选择的文件
      }

      // 获取当前时间
      let dateTime = new Date()
      this.dialogForm.regulationTime2 = this.$dayjs(dateTime).format('YYYY-MM-DD HH:mm:ss')

      // 判断文件类型
      let testFile = file.name.substring(file.name.lastIndexOf('.') + 1).toLowerCase()
      const extension = testFile === 'xlsx' || testFile === 'xls' || testFile === 'pdf'
      if (!extension) {
        this.$message.error('文件上传只能是 pdf/Excel(xlxs、xls) 格式!')
        return false
      } else {
        this.dialogForm.regulationTestPlan = file.name
        this.formData.set('regulationTestPlan', file.raw)
        // 上传一次调频测试方案和一次调频实验报告,才能上传一次调频定值单
        if (!this.dialogForm.regulationTestPlan || !this.dialogForm.regulationTestReport) {
          this.flagUpload = true
        } else {
          this.flagUpload = false
        }
        return true
      }
    },

    onChange3(file, fileList3) {
      // 上传单个文件且能覆盖之前的文件
      if (fileList3.length > 0) {
        this.fileList3 = [fileList3[fileList3.length - 1]] // 获取最后一次选择的文件
      }

      // 获取当前时间
      let dateTime = new Date()
      this.dialogForm.regulationTime3 = this.$dayjs(dateTime).format('YYYY-MM-DD HH:mm:ss')

      let testFile = file.name.substring(file.name.lastIndexOf('.') + 1).toLowerCase()
      const extension = testFile === 'xlsx' || testFile === 'xls' || testFile === 'pdf'
      if (!extension) {
        this.$message.error('文件上传只能是 pdf/Excel(xlxs、xls) 格式!')
        return false
      } else {
        this.dialogForm.regulationTestReport = file.name
        this.formData.set('regulationTestReport', file.raw)
        // 上传一次调频测试方案和一次调频实验报告,才能上传一次调频定值单
        if (!this.dialogForm.regulationTestReport || !this.dialogForm.regulationTestPlan) {
          this.flagUpload = true
        } else {
          this.flagUpload = false
        }
        return true
      }
    },

    onChange4(file, fileList4) {
      // 上传单个文件且能覆盖之前的文件
      if (fileList4.length > 0) {
        this.fileList4 = [fileList4[fileList4.length - 1]] // 获取最后一次选择的文件
      }
      // 获取当前时间
      let dateTime = new Date()
      this.dialogForm.regulationTime4 = this.$dayjs(dateTime).format('YYYY-MM-DD HH:mm:ss')

      let testFile = file.name.substring(file.name.lastIndexOf('.') + 1).toLowerCase()
      const extension = testFile === 'xlsx' || testFile === 'xls' || testFile === 'pdf'
      if (!extension) {
        this.$message.error('文件上传只能是 pdf/Excel(xlxs、xls) 格式!')
        return false
      } else {
        this.dialogForm.responsePlan = file.name
        this.formData.set('responsePlan', file.raw)
        return true
      }
    },

    onChange5(file, fileList5) {
      // 上传单个文件且能覆盖之前的文件
      if (fileList5.length > 0) {
        this.fileList5 = [fileList5[fileList5.length - 1]] // 获取最后一次选择的文件
      }

      // 获取当前时间
      let dateTime = new Date()
      this.dialogForm.regulationTime5 = this.$dayjs(dateTime).format('YYYY-MM-DD HH:mm:ss')

      let testFile = file.name.substring(file.name.lastIndexOf('.') + 1).toLowerCase()
      const extension = testFile === 'xlsx' || testFile === 'xls' || testFile === 'pdf'
      if (!extension) {
        this.$message.error('文件上传只能是 pdf/Excel(xlxs、xls) 格式!')
        return false
      } else {
        this.dialogForm.responseReport = file.name
        this.formData.set('responseReport', file.raw)
        return true
      }
    },
    regulationReportFormChange() {
      if (!this.dialogForm.regulationTestPlan || !this.dialogForm.regulationTestReport) {
        this.$message.warning('请先上传一次调频测试方案和一次调频实验报告')
        return false
      } else {
        return true
      }
    },
    // 预览
    async doPreview(row, col) {
      const res = await getPdf(row[`${col}Id`])
      if (res.fileType !== 'pdf' && res.fileType !== 'xlsx' && res.fileType !== 'xls') {
        console.log(res.fileType)
        this.$message.warning('只支持pdf与excel格式的文件预览')
        return
      }
      let typeList = {
        pdf: 'application/pdf',
        xls: 'application/vnd.ms-excel',
        xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
      }
      const blob = new Blob([res], { type: typeList[res.fileType] })
      if (res.fileType === 'pdf') {
        this.pdf = URL.createObjectURL(blob)
      } else {
        const reader = new FileReader()
        reader.onload = (e) => {
          const data = new Uint8Array(e.target.result)
          let workbook = XLSX.read(data, { type: 'array' }) // 解析数据
          this.tableToHtml(workbook)
        }
        reader.readAsArrayBuffer(blob)
      }
      this.dialogPreVisible = true
    },
    tableToHtml(workbook) {
      var worksheet = workbook.Sheets[workbook.SheetNames[0]]
      // var innerHTML = XLSX.utils.sheet_to_html(worksheet);
      if (document.querySelector('#tableHtml')) {
        document.querySelector('#tableHtml').innerHTML = XLSX.utils.sheet_to_html(worksheet)
        document.querySelector('.table-html-wrap table')
        let trs = document.querySelectorAll('tr')
        trs.forEach((tr) => {
          if (!tr.innerText.trim()) {
            tr.remove()
          }
        })
        document.querySelector('.el-dialog__body').style.overflowX = 'auto'
      }
      let tds = document.querySelectorAll('td')
    },
    // 下载
    async doDownload(row, col, name) {
      let excelName = `${name}`
      const res = await getPdf(row[`${col}Id`])
      if (res.fileType !== 'pdf' && res.fileType !== 'xlsx' && res.fileType !== 'xls') {
        this.$message.warning('只支持pdf与excel格式的文件下载')
        return
      }
      let typeList = {
        pdf: 'application/pdf',
        xls: 'application/vnd.ms-excel',
        xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
      }
      const link = document.createElement('a')
      let blob = new Blob([res], {
        type: typeList[res.fileType],
      })
      // xlsx的文件type

      link.style.display = 'none'
      link.href = URL.createObjectURL(blob)
      link.download = excelName //下载的文件名
      document.body.appendChild(link)
      link.click()
      document.body.removeChild(link)
    },
    isRegulationChange(val) {
      let lists = [
        'deadZone',
        'adjustRatio',
        'startingPowerThreshold',
        'lowerLimit',
        'powerAdjustDeviation',
        'upLimit',
        'startTime',
        'responseTime',
        'adjustTime',
        'companyName',
        'companyId',
        'companyId',
        'onOffFunction',
        'isUpFunction',
        'isLowerFunction',
        'isResponseFunction',
        'agcControl',
      ]
      console.log(val, val)
      if (val == '1') {
        this.disabledDetail = false
      } else {
        for (let k in this.dialogForm) {
          lists.forEach((item) => {
            if (k == item) {
              this.dialogForm[k] = ''
            }
          })
        }
        this.disabledDetail = true
      }
    },
    // 获取升压站接入等级:
    async getVoltageLevelList() {
      const res = await voltageLevelList()
      this.LevelOfAccessList = res.data
      // console.log(res);
    },
    // 获取上调/下调是否投入字典
    async getAdjustRegulationList() {
      const res = await adjustRegulationList()
      this.adjustRegulationList = res.data
      // console.log(res);
    },

    // 获取调度字典
    async getRegulationOrgList() {
      const res = await regulationOrgList()
      this.dispatchList = res.data
    },
    // 获取业主单位字典
    async getOwnersList(val) {
      const res = await queryOwnersList()
      this.ownersList = res.data
      if (val) {
        this.ownersList.forEach((item) => {
          if (item.ownersName == this.$refs.owner.labels) this.$refs.owner.labels = item.ownersId
          // this.dialogForm.ownersId = item.ownersId;
        })
      }
    },
    // 获取试验单位字典
    async getQueryTestingUnitList(val) {
      const res = await queryTestingUnitList()
      this.queryUnitList = res.data
      if (val) {
        this.queryUnitList.forEach((item) => {
          if (item.testingUnitName == this.$refs.testingUnit.labels)
            // this.dialogForm.testingUnitId = item.testingUnitId;
            this.$refs.testingUnit.labels = item.testingUnitId
        })
      }
    },
    // 获取场站名称字典
    // async getQueryStationList() {
    //   const res = await queryStationList();
    //   console.log(res);
    //   this.stationList = res.data;
    // },

    // 弹窗内退出按钮
    isExit() {
      this.addDialogVisible = false
    },
    // 弹窗内重置按钮
    isReset() {
      for (let key in this.dialogForm) {
        this.dialogForm[key] = ''
      }
      if (this.$refs.owner) {
        this.$refs.owner.labels = ''
      }
      if (this.$refs.testingUnit) {
        this.$refs.testingUnit.labels = ''
      }
    },
    // 弹窗内确认新增按钮
    isAdd() {
      // console.log();
      // console.log(this.stationList,'this.stationList')
      // console.log(this.stationList,'this.stationList')
      this.$refs.diaForm.validate(async (v) => {
        if (!v) return
        if (this.addDialogVisibleTitle == '新增' || this.addDialogVisibleTitle == '复制') {
          this.dialogForm.operateCode = '1'
        }
        // 编辑的开关（新增：1；编辑：2）
        if (this.addDialogVisibleTitle == '编辑') {
          this.dialogForm.operateCode = '2'
        }
        this.dialogForm.stationType = '6'
        this.dialogForm.ownersId = this.$refs.owner.labels
        this.dialogForm.testingUnitId = this.$refs.testingUnit.labels

        // this.stationList.forEach((item) => {
        //   if (item.stationName == this.$refs.station.labels)
        //     this.dialogForm.stationId = item.stationId;
        // });

        let delArr = [
          'regulationReportFormId',
          'regulationTestPlanId',
          'regulationTestReportId',
          'responsePlanId',
          'responseReportId',
          'regulationReportForm',
          'regulationTestPlan',
          'regulationTestReport',
          'responsePlan',
          'responseReport',
          'regulationTime1',
          'regulationTime2',
          'regulationTime3',
          'regulationTime4',
          'regulationTime5',
        ]

        delArr.forEach((item) => {
          if (this.dialogForm[item] || this.dialogForm[item] == null) delete this.dialogForm[item]
          //if (this.dialogForm[item]) delete this.dialogForm[item];
        })
        if (this.dialogForm.isResponse === undefined || this.dialogForm.isResponse === null) {
          delete this.dialogForm.isResponse
        } else {
          this.formData.set('isResponse', this.dialogForm.isResponse)
        }

        this.dialogForm.regulationTime = this.dialogForm.regulationTime && this.dialogForm.regulationTime.replace('T', ' ')
        // let formData = new FormData();
        // Object.keys(this.dialogForm).forEach((key) => {
        //   formData.append(key, this.dialogForm[key]);
        // });
        Object.keys(this.dialogForm).forEach((key) => {
          this.formData.set(key, this.dialogForm[key])
        })
        const res = await doInsertOrUpdateEnergyStationInfo(this.formData)
        // console.log(res);
        if (res.code == '000000') {
          this.$message.success(`${this.addDialogVisibleTitle}成功`)
          this.addDialogVisible = false
          this.$refs.photovoltaicTable.getDataInit()
        }
      })
    },
    // 最外部列表的删除按钮
    doDelete() {
      if (this.$refs.photovoltaicTable.multipleSelection.length == 0) {
        this.$message.warning('请选择要删除的数据')
        return
      }
      let params = this.$refs.photovoltaicTable.multipleSelection.map((item) => item.stationId)
      // 确认删除
      this.$confirm('是否确认删除？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(async () => {
        // 发送请求
        const res = await deleteEnergyStationInfo(params)
        console.log(res)
        // 确认删除
        this.$message({
          type: 'success',
          message: '删除成功!',
        })
        this.$refs.photovoltaicTable.getDataInit()
      })
    },
    // 最外部列表的新增按钮
    openAddDialog() {
      this.isReset()
      // this.dialogForm.regulationOrgId = "1";
      // this.dialogForm.isRegulation = '';
      // this.dialogForm.voltageLevelCode = "110";
      // this.dialogForm.adjustRegulationCode = "1";
      // this.dialogForm.isProduction = '';
      this.addDialogVisibleTitle = '新增'
      this.addDialogVisible = true
    },
    // 最外部列表的复制按钮
    openCopyDialog() {
      this.verdict('复制')
    },
    // 最外部列表的编辑按钮
    openEditDialog() {
      this.verdict('编辑')
      this.dialogForm.regulationId = this.$refs.photovoltaicTable.multipleSelection[0]?.regulationId
    },
    verdict(row) {
      if (this.$refs.photovoltaicTable.multipleSelection.length == 0) {
        this.$message.warning(`请选择要${row}的数据`)
        return
      }
      if (this.$refs.photovoltaicTable.multipleSelection.length > 1) {
        this.$message.warning(`最多选择一条数据进行${row}`)
        return
      }
      this.addDialogVisible = true
      this.addDialogVisibleTitle = row
      // console.log(
      //   this.$refs.photovoltaicTable.multipleSelection[0],
      //   "this.$refs.photovoltaicTable.multipleSelection[0]"
      // );
      // console.log(this.$refs.photovoltaicTable.multipleSelection[0].stationCap,'stationCapstationCapstationCap')
      this.dialogForm = {
        ...this.$refs.photovoltaicTable.multipleSelection[0],
      }
      this.dialogForm.regulationTime = this.dialogForm.regulationTime?.replace('T', ' ')
      this.isRegulationChange(this.dialogForm.isRegulation)

      // 文件上传的回显  时间的回显
      if (this.dialogForm.regulationReportForm) {
        if (this.dialogForm.regulationReportForm.createTime) {
          this.dialogForm.regulationTime1 = this.dialogForm.regulationReportForm.createTime.replace('T', ' ')
        }
        this.dialogForm.regulationReportForm = this.dialogForm.regulationReportForm.oldName
      }

      if (this.dialogForm.regulationTestPlan) {
        if (this.dialogForm.regulationTestPlan.createTime) {
          this.dialogForm.regulationTime2 = this.dialogForm.regulationTestPlan.createTime.replace('T', ' ')
        }
        this.dialogForm.regulationTestPlan = this.dialogForm.regulationTestPlan.oldName
      }
      if (this.dialogForm.regulationTestReport) {
        if (this.dialogForm.regulationTestReport.createTime) {
          this.dialogForm.regulationTime3 = this.dialogForm.regulationTestReport.createTime.replace('T', ' ')
        }
        this.dialogForm.regulationTestReport = this.dialogForm.regulationTestReport.oldName
      }

      if (this.dialogForm.responsePlan) {
        if (this.dialogForm.responsePlan.createTime) {
          this.dialogForm.regulationTime4 = this.dialogForm.responsePlan.createTime.replace('T', ' ')
        }
        this.dialogForm.responsePlan = this.dialogForm.responsePlan.oldName
      }

      if (this.dialogForm.responseReport) {
        if (this.dialogForm.responseReport.createTime) {
          this.dialogForm.regulationTime5 = this.dialogForm.responseReport.createTime.replace('T', ' ')
        }
        this.dialogForm.responseReport = this.dialogForm.responseReport.oldName
      }
    },
    // 最外部列表的导出按钮
    async exportExcel() {
      // 导出excel
      let excelName = '光伏模块数据.xlsx'
      const res = await downloadEnergyStationInfos(this.photovoltaicForm)
      const link = document.createElement('a')
      let blob = new Blob([res], {
        type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
      })
      link.style.display = 'none'
      link.href = URL.createObjectURL(blob)
      link.download = excelName //下载的文件名
      document.body.appendChild(link)
      link.click()
      document.body.removeChild(link)
    },
    // 检索按钮
    searchList() {
      this.$refs.photovoltaicTable.getDataInit()
    },
    // 重置按钮
    resetSearchList() {
      for (let key in this.photovoltaicForm) {
        this.photovoltaicForm[key] = ''
      }
      this.photovoltaicForm.stationType = '6'
      this.$refs.photovoltaicTable.getDataInit()
    },
    // 获取协调控制分类
    async getAgcControlList() {
      const res = await agcControlList()
      this.agcControlList = res.data
    },
  },
}
</script>
<style lang="scss" scoped>
.table-html-wrap {
  overflow: hidden;
  overflow-y: auto;
}

.table-html-wrap ::v-deep table {
  // color: red;
  border-right: 1px solid #000;
  border-bottom: 1px solid #000;
  border-collapse: collapse;
  margin: auto;
}

.table-html-wrap ::v-deep table td {
  border-left: 1px solid #000;
  border-top: 1px solid #000;
  white-space: nowrap;
  text-align: center;
  padding: 0.5rem;
}

.table-html-wrap ::v-deep tbody tr:nth-of-type(1) {
  font-weight: bold;
  font-size: 20px;
}
.wrap {
  width: 100%;
  height: 100%;
  /* background-color: rgb(192, 241, 188); */
}

.rowTitle {
  color: #436bfe;
  height: 40px;
  // line-height: 40px;
}

.operateButton {
  cursor: pointer;
  font-size: 12px !important;
  padding: 8px;

  img {
    transform: translateY(-2px);
  }
}

.operateButton::after {
  display: inline-block;
  content: '';
  width: 1px;
  height: 18px;
  margin: 0 3px;
  transform: translate(6px, 3px);
  background: #000;
}

.operateButton:last-child::after {
  display: none;
}

.titleText {
  margin-bottom: 10px;
  color: rgb(95, 124, 206);
}

// .el-dialog .el-form-item--mini {
//   width: 96.5%;
// }
// ::v-deep .el-color-picker__icon, .el-input, .el-textarea{
//   width: 102%;
// }
::v-deep .el-dialog .el-form-item--mini .el-form-item__label {
  font-size: 12px !important;
}

::v-deep .el-select--mini {
  width: 100%;
}

.upload-demo {
  display: inline-block;
}
::v-deep .el-table__empty-block {
  justify-content: left;
  text-align: left;
  padding-left: 40%;
}
::v-deep .el-select-dropdown {
  position: absolute !important;
  top: 80% !important;
  left: 0px !important;
}
// ::v-deep .el-input--mini  {
//   width: 92%;
// }
// ::v-deep .el-select--mini {
//   width: 100%;
// }
// .afterMW::after{
//   content: 'MW';
//   display: inline-block;
//   height: 100%;
// }
</style>
